package com.tan.multitasking;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
/**
 * The Component that draws the balls.
 *  组件用于绘画这个球。
 * */
public class BallComponent extends JPanel {
    private static final int DEFAULT_WIDTH = 450;
    private static final int DEFAULT_HEIGHT = 450;

    private java.util.List<Ball> balls = new ArrayList<>();
    /**
     * Add a ball to the component
     *将球添加到组件
     * */
    public void add(Ball ball){
        balls.add(ball);
    }
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        Graphics2D g2 =(Graphics2D) g;
        for (Ball ball:balls){
            g2.fill(ball.getShape());
        }
    }
    public Dimension getPreferredSize(){
        return new Dimension(DEFAULT_WIDTH,DEFAULT_HEIGHT);
    }
}
